/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JIFRegistrarDevolucao.java
 *
 * Created on 18/06/2011, 10:45:09
 */
package br.unesp.demac.bcc.soo.view.aluguel;

import br.unesp.demac.bcc.soo.bean.Aluguel;
import br.unesp.demac.bcc.soo.bean.AluguelRel;
import br.unesp.demac.bcc.soo.bean.Dvd;
import br.unesp.demac.bcc.soo.bean.Pessoa;
import br.unesp.demac.bcc.soo.dao.AluguelDAO;
import br.unesp.demac.bcc.soo.dao.AluguelDAOImp;
import br.unesp.demac.bcc.soo.dao.DvdDAO;
import br.unesp.demac.bcc.soo.dao.DvdDAOImp;
import br.unesp.demac.bcc.soo.util.Dialog;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author flavioam
 */
public class JIFRegistrarDevolucao extends javax.swing.JInternalFrame {

    /** Creates new form JIFRegistrarDevolucao */
    public JIFRegistrarDevolucao() {
        initComponents();
        btnSalvaDevolucao.setEnabled(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel3 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        txtCodDvd = new javax.swing.JTextField();
        btnProcurarDvd = new javax.swing.JButton();
        txtNomeDvd = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        txtModalidadeDvd = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        txtClassDvd = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        txtGeneroDvd = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtCodCliente = new javax.swing.JTextField();
        txtNomeCliente = new javax.swing.JTextField();
        txtCpfCliente = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        txtTelResid = new javax.swing.JTextField();
        txtEnd = new javax.swing.JTextField();
        txtTelCel = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabelaAluguel = new javax.swing.JTable();
        btnCancela = new javax.swing.JButton();
        btnSalvaDevolucao = new javax.swing.JButton();

        setClosable(true);
        setTitle("Registro de Devolução");
        setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/br/unesp/demac/bcc/soo/img/ico16x16/inIcon.png"))); // NOI18N

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Dvd"));

        jLabel7.setText("Cód. Dvd:");

        jLabel8.setText("Nome:");

        txtCodDvd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtCodDvdActionPerformed(evt);
            }
        });

        btnProcurarDvd.setText("Procurar");
        btnProcurarDvd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnProcurarDvdActionPerformed(evt);
            }
        });

        txtNomeDvd.setEnabled(false);

        jLabel9.setText("Modalidade:");

        txtModalidadeDvd.setEnabled(false);

        jLabel11.setText("Class.:");

        txtClassDvd.setEnabled(false);
        txtClassDvd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtClassDvdActionPerformed(evt);
            }
        });

        jLabel12.setText("Gênero:");

        txtGeneroDvd.setEnabled(false);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8))
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(15, 15, 15)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtModalidadeDvd)
                            .addComponent(txtNomeDvd, javax.swing.GroupLayout.DEFAULT_SIZE, 253, Short.MAX_VALUE)))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtCodDvd, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnProcurarDvd)))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel12)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtGeneroDvd, javax.swing.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtClassDvd, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(260, Short.MAX_VALUE))
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jLabel9)
                .addContainerGap(661, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(txtCodDvd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnProcurarDvd))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(txtNomeDvd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel9)
                            .addComponent(txtModalidadeDvd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel11)
                            .addComponent(txtClassDvd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel12)
                            .addComponent(txtGeneroDvd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Cliente"));

        jLabel1.setText("Cód. Cliente:");

        jLabel2.setText("Nome:");

        jLabel3.setText("Cpf: ");

        txtCodCliente.setEnabled(false);

        txtNomeCliente.setEnabled(false);

        txtCpfCliente.setEnabled(false);

        jLabel4.setText("Tel. Resid.:");

        jLabel5.setText("Tel. Cel.:");

        jLabel6.setText("End.:");

        txtTelResid.setEnabled(false);
        txtTelResid.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtTelResidActionPerformed(evt);
            }
        });

        txtEnd.setEnabled(false);

        txtTelCel.setEnabled(false);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtCodCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtNomeCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtCpfCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(24, 24, 24)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel4)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(jLabel6))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtEnd, javax.swing.GroupLayout.DEFAULT_SIZE, 271, Short.MAX_VALUE)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(txtTelResid, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(txtTelCel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 121, Short.MAX_VALUE)))))
                .addContainerGap(83, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtCodCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(txtTelResid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(txtNomeCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(txtCpfCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(txtTelCel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(txtEnd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Itens Restantes"));

        tabelaAluguel.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Cód. Dvd", "Dvd", "Valor", "Data Locação", "Data Devolução"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.Double.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tabelaAluguel.setEnabled(false);
        jScrollPane1.setViewportView(tabelaAluguel);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 707, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        btnCancela.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/unesp/demac/bcc/soo/img/ico48x48/cancel.png"))); // NOI18N
        btnCancela.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelaActionPerformed(evt);
            }
        });

        btnSalvaDevolucao.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/unesp/demac/bcc/soo/img/ico48x48/inIcon48x48.png"))); // NOI18N
        btnSalvaDevolucao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalvaDevolucaoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(292, 292, 292)
                        .addComponent(btnSalvaDevolucao)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnCancela)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(9, 9, 9)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnSalvaDevolucao)
                    .addComponent(btnCancela)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtTelResidActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtTelResidActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_txtTelResidActionPerformed

    private void txtCodDvdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtCodDvdActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_txtCodDvdActionPerformed

    private void btnProcurarDvdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnProcurarDvdActionPerformed
        try {
            // TODO add your handling code here:

            DvdDAO dDao = new DvdDAOImp();
            Dvd d = dDao.selecionaDvdAlugadoById(Integer.parseInt(txtCodDvd.getText()));


            if (d == null) {

                Dialog.errorDialog("Dvd não encontrado ou não Alugado!");
            } else {

                txtClassDvd.setText(String.valueOf(d.getClassificacao()));
                txtGeneroDvd.setText(d.getGenero());
                txtModalidadeDvd.setText(d.getModalidade().getNome());
                txtNomeDvd.setText(d.getNome());

                AluguelDAO aDao = new AluguelDAOImp();
                ArrayList<Aluguel> aList = aDao.selecionaAlugueisAtivosByDvd(d);

                DefaultTableModel model = (DefaultTableModel) tabelaAluguel.getModel();
                SimpleDateFormat sd = new SimpleDateFormat("dd/MM/yyyy");

                for (Aluguel a : aList) {

                    Pessoa p = a.getPessoa();

                    txtNomeCliente.setText(p.getNome());
                    txtCpfCliente.setText(p.getCpf());
                    txtEnd.setText(p.getEndereco().getEndereco());
                    txtTelCel.setText(p.getContato().getTelefoneCelular());
                    txtTelResid.setText(p.getContato().getTelefoneResidencial());
                    txtCodCliente.setText(String.valueOf(p.getIdPessoa()));

                    for (AluguelRel aRel : a.getAluguelRel()) {

                        Object[] newRow = new Object[5];


                        newRow[0] = aRel.getDvd().getIdDvd();
                        newRow[1] = aRel.getDvd().getNome();
                        newRow[2] = aRel.getValor();
                        newRow[3] = sd.format(a.getDataLocacao());
                        newRow[4] = sd.format(aRel.getDataDevolucao());

                        model.addRow(newRow);
                    }
                }




                //preenche tabela com dados de outros possivies dvds alugados por esse cliente

                //ArrayList<Dvd> = dDao.selecionaDvdAlugadoByCliente(null)

                btnSalvaDevolucao.setEnabled(true);
                btnCancela.setEnabled(true);
                btnProcurarDvd.setEnabled(false);
                txtCodDvd.setEnabled(false);
            }
        } catch (Exception ex) {
            Dialog.errorDialog(ex.getMessage());
        }
    }//GEN-LAST:event_btnProcurarDvdActionPerformed

    private void txtClassDvdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtClassDvdActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_txtClassDvdActionPerformed

    private void btnCancelaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelaActionPerformed
        // TODO add your handling code here:
        btnSalvaDevolucao.setEnabled(false);
        btnProcurarDvd.setEnabled(true);
        txtCodDvd.setEnabled(true);

        txtClassDvd.setText("");
        txtCodCliente.setText("");
        txtCodDvd.setText("");
        txtCpfCliente.setText("");
        txtEnd.setText("");
        txtGeneroDvd.setText("");
        txtModalidadeDvd.setText("");
        txtNomeCliente.setText("");
        txtNomeDvd.setText("");
        txtTelCel.setText("");
        txtTelResid.setText("");
        DefaultTableModel tableModel = (DefaultTableModel) tabelaAluguel.getModel();
        tableModel.setNumRows(0);

        txtClassDvd.setEnabled(false);
        txtCpfCliente.setEnabled(false);
        txtEnd.setEnabled(false);
        txtGeneroDvd.setEnabled(false);
        txtModalidadeDvd.setEnabled(false);
        txtNomeCliente.setEnabled(false);
        txtNomeDvd.setEnabled(false);
        txtTelCel.setEnabled(false);
        txtTelResid.setEnabled(false);

        txtCodCliente.requestFocus();

    }//GEN-LAST:event_btnCancelaActionPerformed

    private void btnSalvaDevolucaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalvaDevolucaoActionPerformed
        // TODO add your handling code here:

        try {

            AluguelDAO aDao = new AluguelDAOImp();

            Dvd d = new Dvd();
            d.setIdDvd(Integer.parseInt(txtCodDvd.getText()));

            aDao.efetuaDevolucao(d);

            Dialog.sucessoDialog("Dvd devolvido com sucesso!");

            btnSalvaDevolucao.setEnabled(false);
            btnProcurarDvd.setEnabled(true);
            txtCodDvd.setEnabled(true);

            txtClassDvd.setText("");
            txtCodCliente.setText("");
            txtCodDvd.setText("");
            txtCpfCliente.setText("");
            txtEnd.setText("");
            txtGeneroDvd.setText("");
            txtModalidadeDvd.setText("");
            txtNomeCliente.setText("");
            txtNomeDvd.setText("");
            txtTelCel.setText("");
            txtTelResid.setText("");

            txtClassDvd.setEnabled(false);
            txtCpfCliente.setEnabled(false);
            txtEnd.setEnabled(false);
            txtGeneroDvd.setEnabled(false);
            txtModalidadeDvd.setEnabled(false);
            txtNomeCliente.setEnabled(false);
            txtNomeDvd.setEnabled(false);
            txtTelCel.setEnabled(false);
            txtTelResid.setEnabled(false);

            DefaultTableModel model = (DefaultTableModel) tabelaAluguel.getModel();
            model.setRowCount(0);

            txtCodCliente.requestFocus();

        } catch (Exception e) {

            Dialog.errorDialog(e.getMessage());
        }
    }//GEN-LAST:event_btnSalvaDevolucaoActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancela;
    private javax.swing.JButton btnProcurarDvd;
    private javax.swing.JButton btnSalvaDevolucao;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tabelaAluguel;
    private javax.swing.JTextField txtClassDvd;
    private javax.swing.JTextField txtCodCliente;
    private javax.swing.JTextField txtCodDvd;
    private javax.swing.JTextField txtCpfCliente;
    private javax.swing.JTextField txtEnd;
    private javax.swing.JTextField txtGeneroDvd;
    private javax.swing.JTextField txtModalidadeDvd;
    private javax.swing.JTextField txtNomeCliente;
    private javax.swing.JTextField txtNomeDvd;
    private javax.swing.JTextField txtTelCel;
    private javax.swing.JTextField txtTelResid;
    // End of variables declaration//GEN-END:variables
}
